package com.xt.base.pojo;

import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;

import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.builder.HashCodeBuilder;

import com.xt.base.dao.hibernate.code.IAutoCreateCode;
import com.xt.base.util.json.Jsoner;

@SuppressWarnings("unchecked")
public abstract class BasePOJO extends Jsoner implements Serializable, Comparable {

	private static final long serialVersionUID = 6723911731346857549L;

	/** * code ** */
	private String code;

	/** * version ** */
	private Integer version;
	
	public BasePOJO(){}

	public String[] getJustProperties() {
		return null;
	}

	public String[] getUnpaseProperties() {
		return null;
	}
	
	public void afterSetCode() {
	}

	public Set<IAutoCreateCode> getTargets() {
		Set<IAutoCreateCode> set = new HashSet<IAutoCreateCode>();
		if (isEmpty(code))
			set.add((IAutoCreateCode) this);
		return set;
	}
	
	protected boolean isEmpty(String string){
		return StringUtils.isEmpty(string == null?null:string.trim());
	}
	
	public int compareTo(Object o) {
		return 0;
	}

	public int hashCode() {
		return new HashCodeBuilder().append(code).toHashCode();
	}


	/**
	 * @hibernate.id length="25" generator-class="assigned"
	 *               unsaved-value="version"
	 * @return code
	 */
	public String getCode() {
		return code;
	}

	public void setCode(String code) {
		this.code = code;
	}

	/**
	 * @hibernate.version
	 */
	public Integer getVersion() {
		return version;
	}

	public void setVersion(Integer version) {
		this.version = version;
	}
}
